package org.ezplatform.office.meeting.info.web.rest;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.ezplatform.cloud.api.component.attachment.AttachmentUtilsService;
import org.ezplatform.cloud.api.component.popuser.PopUserScopeUtilService;
import org.ezplatform.cloud.api.system.user.UserApiService;
import org.ezplatform.cloud.common.controller.BaseController;
import org.ezplatform.cloud.common.log.LogService;
import org.ezplatform.core.common.WebUser;
import org.ezplatform.core.web.util.WebUtils;
import org.ezplatform.core.web.view.OperationResult;
import org.ezplatform.mobile.util.common.service.CommonService;
import org.ezplatform.mobile.util.paramdata.service.MobileParamdataService;
import org.ezplatform.office.meeting.common.util.CycleMeetingThread;
import org.ezplatform.office.meeting.common.util.MeetingSendMsgUtils;
import org.ezplatform.office.meeting.common.util.MeetingUtils;
import org.ezplatform.office.meeting.info.entity.ApplyRecord;
import org.ezplatform.office.meeting.info.entity.MeetingScope;
import org.ezplatform.office.meeting.info.entity.SignedAddress;
import org.ezplatform.office.meeting.info.entity.SignedInfo;
import org.ezplatform.office.meeting.info.entity.Urlconvert;
import org.ezplatform.office.meeting.info.service.ApplyRecordDingService;
import org.ezplatform.office.meeting.info.service.ApplyRecordService;
import org.ezplatform.office.meeting.info.service.JdfMeetingService;
import org.ezplatform.office.meeting.info.service.MeetingScopeService;
import org.ezplatform.office.meeting.info.service.SignedAddressService;
import org.ezplatform.office.meeting.info.service.SignedInfoService;
import org.ezplatform.office.meeting.info.service.UrlconvertService;
import org.ezplatform.office.meeting.memo.service.MemoInfoService;
import org.ezplatform.office.meeting.notice.entity.NoticeInfo;
import org.ezplatform.office.meeting.notice.service.NoticeInfoService;
import org.ezplatform.office.meeting.notice.service.NoticeTurnoverService;
import org.ezplatform.office.meeting.setting.boardroom.entity.BoardroomSet;
import org.ezplatform.office.meeting.setting.boardroom.service.BoardroomSetService;
import org.ezplatform.office.meeting.setting.serve.entity.ServeSet;
import org.ezplatform.office.meeting.setting.serve.service.ServeSetService;
import org.ezplatform.office.meeting.setting.type.entity.MeetingType;
import org.ezplatform.office.meeting.setting.type.service.MeetingTypeService;
import org.ezplatform.office.meeting.task.service.MeetingTaskInfoService;
import org.ezplatform.util.DateUtils;
import org.ezplatform.util.JsonUtils;
import org.ezplatform.util.StringUtils;
import org.ezplatform.util.UuidUtils;
import org.ezplatform.util.ValidateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.swetake.util.Qrcode;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * 
 * 会议管理--会议申请
 *
 */
@RestController("applyrecordsfac")
@RequestMapping("api/meeting")
public class ApplyRecordApiController extends BaseController {
	
	private static long testQueryApplyRecordCount=0;
	private static long testQueryApplyRecordByIdCount=0;

	private final Logger logger = LoggerFactory.getLogger(ApplyRecordApiController.class);
	
	private String msg = "";
	
	@Autowired
	private ApplyRecordDingService applyRecordDingService;

	@Autowired
	private ApplyRecordService applyRecordService;
	
	@Autowired
	private BoardroomSetService boardroomSetService;

	@Autowired
	private MeetingScopeService meetingScopeService;

	@Autowired
	private NoticeInfoService noticeInfoService;

	@Autowired
	private UserApiService userApiService;
	
	@Autowired
	private SignedAddressService signedAddressService;
	
	@Autowired
	private SignedInfoService signedInfoService;
	
	@Autowired
    private MeetingTypeService meetingTypeService;
	
	@Autowired
	private MemoInfoService memoInfoService;
	
	@Autowired
	private MeetingTaskInfoService meetingTaskInfoService;
	
	@Autowired
	private PopUserScopeUtilService popUserScopeUtilService;
	
	@Autowired
	private AttachmentUtilsService attachmentUtilsService;
	
	@Autowired
	private ServeSetService serveSetService;
	
	@Autowired
	private UrlconvertService urlconvertService;
	
	@Autowired
	private MeetingSendMsgUtils meetingSendMsgUtils;

	@Autowired
	private NoticeTurnoverService noticeTurnoverService;
	
	@Autowired
	private MobileParamdataService mobileParamdataService;

	@Autowired
	private MeetingUtils meetingUtils;
	
	@Autowired
	private LogService logService;
	
	@Autowired
	private CommonService commonService;
	
	@Autowired
    private AttachmentUtilsService attchService;
	
	@Autowired
    private JdfMeetingService jdfMeetingService;
	
	@ApiOperation(value = "会议室是否被占用", notes = "会议室是否被占用")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "SDate", value = "开始时间", required = true, paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "EDate", value = "结束时间", required = true, paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "boardRoomId", value = "会议室ID", required = true, paramType = "query", dataType = "String") })
	@RequestMapping(value = "/boardRoomIsExist", method = RequestMethod.POST, produces = {"application/json; charset=UTF-8" })
	public OperationResult boardRoomIsExist(String SDate,String EDate,String boardRoomId,HttpServletRequest request) {
		logger.info("--boardRoomIsExist--");
		logger.info("--SDate:"+SDate);
		logger.info("--EDate:"+EDate);
		logger.info("--boardRoomId:"+boardRoomId);
		String applyRecordId = request.getParameter("applyRecordId");
		List<ApplyRecord> list = this.applyRecordService.getApplyRecordByApp(SDate,EDate,boardRoomId,applyRecordId);
		if(list == null||list.size()==0) {
			return OperationResult.buildSuccessResult("notExist");
		}else {
			return OperationResult.buildSuccessResult("exist");
		}
	}
	
	@ApiOperation(value = "实体类是否存在", notes = "实体类是否存在")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "id", value = "会议申请ID", required = true, paramType = "query", dataType = "String") })
	@RequestMapping(value = "/entityIsExist", method = RequestMethod.POST, produces = {"application/json; charset=UTF-8" })
	public OperationResult entityIsExist(String id) {
		ApplyRecord entity = this.applyRecordDingService.findOne(id);
		if(entity == null) return OperationResult.buildSuccessResult("notExist");
		else return OperationResult.buildSuccessResult("exist");
	}
	
	@RequestMapping(value = "/cycleEntityIsExist", method = RequestMethod.POST)
    @ResponseBody
	public OperationResult cycleEntityIsExist(HttpServletRequest request) {
		String id = request.getParameter("id");
        String corpId = request.getParameter("corpId");
		List<ApplyRecord> list = this.applyRecordDingService.findListByProperty("cycleId", id, corpId);
		if(CollectionUtils.isEmpty(list)) return OperationResult.buildSuccessResult("notExist");
		else return OperationResult.buildSuccessResult("exist");
	}
	
	/**
	 * 会议申请详细页面数据
	 * 
	 * @param request
	 * @return
	 */
	@ApiOperation(value = "会议申请", notes = "新建、编辑查看会议申请详细信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "userId", value = "当前用户ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "corpId", value = "单位ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "token", value = "token", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "boardroomId", value = "会议室id", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "type", value = "会议室id", required = true, paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "id", value = "会议申请ID", required = true, paramType = "query", dataType = "String") })
	@RequestMapping(value = "/applyRecordInfo", method = RequestMethod.GET, produces = {"application/json; charset=UTF-8" })
	public OperationResult getApplyRecordInfo(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			String token = request.getParameter("token");
			String corpId = request.getParameter("corpId");
			String userId = request.getParameter("userId");
			String id = request.getParameter("id");
			String type = request.getParameter("type");
			String boardroomId = request.getParameter("boardroomId");
			String fileId = "";
			if(StringUtils.isNotEmpty(id)) {
				ApplyRecord applyRecord = this.applyRecordDingService.findOne(id);
				if(applyRecord == null) {
	            	map.put("isDeleted", true);
	            	return OperationResult.buildSuccessResult(map);
	            }
				fileId = applyRecord.getFileId();
			}
			//查询会议content
			if("view".equals(type)){
				map = this.applyRecordDingService.getViewApplyRecordContent(request,id,userId,corpId,token);
			}else{
				map = this.applyRecordDingService.getApplyRecordContent(id,userId,corpId,token);
			}
			String messagePushSW = commonService.getMessagePush(corpId, token,"meeting");
			map.put("messagePushSW", messagePushSW);
			Object attIdJson = this.applyRecordDingService.transformAttachmentPlanform2Dd(StringUtils.null2String(fileId), token);
			map.put("attIdJson", attIdJson);
            map.put("fileIds", StringUtils.null2String(fileId));
			map.put("isDeleted", false);
            if(StringUtils.isNotEmpty(boardroomId)){
            	List serveSetList = this.serveSetService.getBoardRoomServeTreeDataList(corpId,boardroomId);
                map.put("serveSetList", serveSetList);
                BoardroomSet boardroom = this.boardroomSetService.findOne(boardroomId);
                map.put("boardRoom", boardroom);
            }
           
		} catch (Exception e) {
			e.printStackTrace();
			return OperationResult.buildFailureResult("获取失败");
		}
		return OperationResult.buildSuccessResult(map);
	}

	/**
	 * 会议申请详细页面数据
	 *
	 * @param request
	 * @return
	 */
	@ApiOperation(value = "会议申请", notes = "新建、编辑查看会议申请详细信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "id", value = "会议id", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "corpId", value = "单位ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "boardroomId", value = "会议室id", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "startTime", value = "开始时间", required = true, paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "endTime", value = "结束时间", required = true, paramType = "query", dataType = "String") })
	@RequestMapping(value = "/validateMeetingTime", method = RequestMethod.GET, produces = {"application/json; charset=UTF-8" })
	public OperationResult validateMeetingTime(HttpServletRequest request) {
		Map<String, Object> result = new HashMap<>();
		result.put("type", "1");
		String id = StringUtils.null2String(request.getParameter("id"));
		String corpId = StringUtils.null2String(request.getParameter("corpId"));
		String startTime = request.getParameter("startTime");
		String endTime = request.getParameter("endTime");
		String boardroomId = request.getParameter("boardroomId");
		String isCycle = request.getParameter("isCycle");
		//验证会议开始结束时间是否在会议室的范围内
//		Date start = DateUtils.parseDate(startTime);
//		Date end = DateUtils.parseDate(endTime);
//		if(start.getTime() == end.getTime()){
			msg = this.boardroomSetService.checkTime(boardroomId,startTime, endTime,corpId);
			if (StringUtils.isNotEmpty(msg)) {
				result.put("type", "0");
				result.put("msg", msg);
				return OperationResult.buildSuccessResult(result);
			}
//		}
		//验证会议室在会议开始结束时间范围内是否已有会议
		msg = this.applyRecordDingService.checkApplyRecordDate(id,startTime, endTime,boardroomId, corpId);
		if (StringUtils.isNotEmpty(msg)) {
			result.put("type", "0");
			result.put("msg", msg);
			return OperationResult.buildSuccessResult(result);
		}
		//检测该会议室再周期内是否被占用
        if("1".equals(isCycle)) {
        	ApplyRecord entity = new ApplyRecord();
        	String cycleType = request.getParameter("cycleType");
            entity.setStartTime(startTime);
            entity.setEndTime(endTime);
            entity.setBoardroomId(boardroomId);
            entity.setIsCycle(Integer.parseInt(isCycle));
        	entity.setCycleType(Integer.parseInt(cycleType));
        	entity.setCycleValue(request.getParameter("cycleValue"));
        	entity.setCycleEndTime(request.getParameter("cycleEndTime"));
        	List<Map<String, String>> cyclelist = this.applyRecordService.getCycleDateList(entity);
        	msg = this.applyRecordService.checkCycleApplyRecordDate(entity, cyclelist, corpId);
        	if (StringUtils.isNotEmpty(msg)) {
        		result.put("type", "0");
    			result.put("msg", msg);
    			return OperationResult.buildSuccessResult(result);
        	}
        }
		return OperationResult.buildSuccessResult(result);
	}

	/**
	 *  保存会议申请信息
	 * @param request
	 * @param message
	 * @return
	 */
	@ApiOperation(value = "保存会议申请信息", notes = "保存会议申请信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "userId", value = "当前用户ID", required = true, paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "userName", value = "用户名", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "corpId", value = "单位ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "token", value = "token", required = true, paramType = "query", dataType = "String") })
	@RequestMapping(value = "/saveInfo", method = RequestMethod.POST)
	public OperationResult saveInfo(HttpServletRequest request, @RequestBody String message) {
		logger.info("保存会议申请信息开始");
		String token = request.getParameter("token");
		String corpId = request.getParameter("corpId");
		String userId = request.getParameter("userId");
		BoardroomSet room = null;
		try {
			Map<String, Object> map = JsonUtils.readValue(message);
			
			ApplyRecord applyRecord = null;
			ApplyRecord oldApplyRecord = null;
			String id =  StringUtils.null2String(map.get("id"));
			if (StringUtils.isNotEmpty(id)) {
				applyRecord = this.applyRecordDingService.findOne(id);
				oldApplyRecord = this.applyRecordCopy(applyRecord);//用于判断会议信息是否修改
				if (applyRecord == null) {
					applyRecord = new ApplyRecord();
				}
			} else {
				applyRecord = new ApplyRecord();
			}
			
			if("".equals(StringUtils.null2String(applyRecord.getId()))){
				applyRecord.setCreatedBy(userId);
				applyRecord.setCorpId(corpId);
			}else{
				applyRecord.setLastModifiedBy(userId);
			}
			
	        //保存前 验证
	        // 验证名称
			String name =  StringUtils.null2String(map.get("name"));
			/*msg = this.applyRecordDingService.checkApplyRecordInfo(id, name, 1, corpId);
			if (StringUtils.isNotEmpty(msg)) {
	            return OperationResult.buildFailureResult(msg);
			}*/
			// 会议结束时间
			String startTimeStr = StringUtils.null2String(map.get("startTime"));
			String startTime = "";
			if (StringUtils.isNotEmpty(startTimeStr)) {
			    startTime = DateUtils.formatShortTime(new Date(Long.valueOf(startTimeStr)));
			}
            String endTimeStr =  StringUtils.null2String(map.get("endTime"));
            String endTime = "";
            if (StringUtils.isNotEmpty(endTimeStr)) {
                endTime = DateUtils.formatShortTime(new Date(Long.valueOf(endTimeStr)));
            }
            String isApprove = "";
            String  boardroomId =  StringUtils.null2String(map.get("boardroomId"));
            // 会议开始时间
 			applyRecord.setStartTime(startTime);
 			// 会议结束时间
            applyRecord.setEndTime(endTime);
            int isCycle = Integer.parseInt(StringUtils.null2String(map.get("isCycle")));
 			// 周期性会议
 			applyRecord.setIsCycle(isCycle);
 			if(isCycle == 1) {
 				// 重复方式
 				applyRecord.setCycleType(Integer.parseInt(StringUtils.null2String(map.get("cycleType"))));
 				//周期值
 				applyRecord.setCycleValue(StringUtils.null2String(map.get("cycleValue")));
 				// 周期结束时间
 				applyRecord.setCycleEndTime(StringUtils.null2String(map.get("cycleEndTime")));
 			}
 			List<Map<String, String>> cyclelist = null;
 			// 会议室id
 			applyRecord.setBoardroomId(boardroomId);
            if(StringUtils.isNotEmpty(boardroomId)) {
            	//验证会议开始结束时间是否在会议室的范围内
//                Date start = DateUtils.parseDate(startTime);
//                Date end = DateUtils.parseDate(endTime);
//                if(start.getTime() == end.getTime()){
                	msg = this.boardroomSetService.checkTime(boardroomId,startTime, endTime,corpId);
                    if (StringUtils.isNotEmpty(msg)) {
                    	return OperationResult.buildFailureResult(msg);
                    }
//                }
                //验证会议室在会议开始结束时间范围内是否已有会议
    	        msg = this.applyRecordDingService.checkApplyRecordDate(id,startTime, endTime,boardroomId, corpId);
    	        if (StringUtils.isNotEmpty(msg)) {
    	        	return OperationResult.buildFailureResult(msg);
    	        }
    	        //检测该会议室在周期内是否被占用
    	        if(applyRecord.getIsCycle() == 1) {
    	        	cyclelist = this.applyRecordService.getCycleDateList(applyRecord);
    	        	msg = this.applyRecordService.checkCycleApplyRecordDate(applyRecord, cyclelist, corpId);
    	        	if (StringUtils.isNotEmpty(msg))  return OperationResult.buildFailureResult(msg);
    	        }
    	        //验证会议室是否审批
    	        room = this.boardroomSetService.findOne(boardroomId);
    	        if(room != null){
    	        	isApprove = StringUtils.null2String(room.getIsApprove());
    	        }
    	        //状态修改
    	        //String nStatus = ValidateUtils.filter(request.getParameter("nStatus"));
    	        if(StringUtils.equals(isApprove, "0")){//不需要审批
    	        	applyRecord.setStatus(1);
    	    	}else{
    	    		applyRecord.setStatus(0);
    	    	}
            }else {
            	if(applyRecord.getIsCycle() == 1) {
    	        	cyclelist = this.applyRecordService.getCycleDateList(applyRecord);
    	        }
            	isApprove = "0";
            	applyRecord.setStatus(1);
            }
	        
			//会议创建人
			applyRecord.setCreatedBy(userId);
			//会议单位
			applyRecord.setCorpId(corpId);
			// 会议名称
			applyRecord.setName(name);
			// 会议类型
			applyRecord.setMeetingTypeId(StringUtils.null2String(map.get("meetingType")));
			// 会议内容
			applyRecord.setContent(StringUtils.null2String(map.get("content")));
			//消息推送
			applyRecord.setMessagePush(StringUtils.null2String(map.get("messagePush")));
			//会议备注
			applyRecord.setRemark(StringUtils.null2String(map.get("remark")));
			//附件
			applyRecord.setFileId(StringUtils.null2String(map.get("fileId")));
			// 主持人
			String emceeUserJsonStr = StringUtils.null2String(map.get("jsonStrEmceeUser"));
			String emceeUser = StringUtils.null2String(applyRecord.getEmceeUser());
			if ("".equals(emceeUser)) {
				emceeUser = UuidUtils.UUID();
				applyRecord.setEmceeUser(emceeUser);
			}
			this.popUserScopeUtilService.saveScopeData("oa_meeting_apply_record_scope", emceeUser, emceeUserJsonStr,
					"oa_meeting_apply_record", "emcee_user");
			// 纪要员
			String memoUserJsonStr = StringUtils.null2String(map.get("jsonStrMemoUser"));
			String memoUser = StringUtils.null2String(applyRecord.getMemoUser());
			if ("".equals(memoUser)) {
				memoUser = UuidUtils.UUID();
				applyRecord.setMemoUser(memoUser);
			}
			this.popUserScopeUtilService.saveScopeData("oa_meeting_apply_record_scope", memoUser, memoUserJsonStr,
					"oa_meeting_apply_record", "memo_user");
			// 参会人
			String attendUserJsonStr = StringUtils.null2String(map.get("jsonStrAttendUser"));
			String attendUser = StringUtils.null2String(applyRecord.getAttendUser());
			if ("".equals(attendUser)) {
				attendUser = UuidUtils.UUID();
				applyRecord.setAttendUser(attendUser);
			}
			this.popUserScopeUtilService.saveScopeData("oa_meeting_apply_record_scope", attendUser, attendUserJsonStr,
					"oa_meeting_apply_record", "attend_user");

			// 会前提醒
			applyRecord.setIsNotice(Integer.valueOf(StringUtils.null2String(map.get("isNotice"))));
			// 提醒方式
			applyRecord.setNoticeType(StringUtils.null2String(map.get("noticeType")));
			// 提醒时间
			applyRecord.setNoticeTime(StringUtils.null2String(map.get("noticeTime")));
			
			// 会议签到
			String isSigned = StringUtils.null2String(map.get("isSigned"));
			applyRecord.setIsSigned(Integer.valueOf(isSigned));
			String signedType = "";
			if("1".equals(isSigned)){
				// 签到时间
				applyRecord.setSignedTime(StringUtils.null2String(map.get("signedTime")));
				signedType = StringUtils.null2String(map.get("signedType"));
				applyRecord.setSignedType(signedType);
				if("1".equals(signedType) || "2".equals(signedType)){
					applyRecord.setSignedRange(StringUtils.null2String(map.get("signedRange")));
				}
			}
			
			// 会议服务
			applyRecord.setMeetingServe(StringUtils.null2String(map.get("meetingServe")));
			// reason
			applyRecord.setReason("");
			
			//设置一些判断会议信息是否有修改得变量
			String addrListJson = StringUtils.null2String(map.get("addressList"));
			boolean isEdit = StringUtils.isEmpty(applyRecord.getId()) ? false : true;
	        boolean meetingInfoIsChange = false;
	        List<String> oldUserIdList = null;
	        if(isEdit) {
	        	meetingInfoIsChange = isEntityChanged(applyRecord, id, oldApplyRecord, addrListJson, corpId);
	        	oldUserIdList = this.applyRecordService.getApplyRecordUserList(applyRecord, TOKEN);
	        }
			
	        //保存
			applyRecord = this.applyRecordDingService.save(applyRecord);
			//记录新建日志
	        if(StringUtils.isEmpty(id) && logService.checkOptLog(corpId, "meeting:start:02", TOKEN)) {//判断是否记录日志
	        	this.logService.saveModuleLog("meeting:start:02", applyRecord.getName(), "");  
	        }
			String recordId = "";
			if(applyRecord != null){
				recordId = StringUtils.null2String(applyRecord.getId());
			}
			
			if(!"".equals(recordId)){
				List<String> newUserIdList = this.applyRecordService.getApplyRecordUserList(applyRecord, TOKEN);
	        	List<String> addList = null;
	        	List<String> noticeUpdateList = null;
				if("1".equals(isSigned) && ("1".equals(signedType) || "2".equals(signedType))){
	        		this.signedAddressService.saveSignedAddress(recordId, addrListJson);
				}
    			
				if(!"0".equals(isApprove)){
					List<String> scopeList = new ArrayList<String>();
	    			scopeList.add(room.getAdminUserScope());
	    			List<MeetingScope> msList = this.meetingScopeService.getMeetingScopeList("oa_meeting_boardroom_set",
	    					"admin_user_scope", scopeList, true);
	    			if (msList != null && msList.size()>0) {
	    				// 推送申请---会议室管理员
	    				this.noticeInfoService.saveNoticeInfoIsApply(applyRecord, msList);
	    			}
				}else{
					//this.applyRecordDingService.editApplyRecordInfo(applyRecord.getId(),"1","", "",token);
					if(isEdit) {
	        			addList = new ArrayList<String>();
	                	noticeUpdateList = new ArrayList<String>();
	                	//获取新增加的参会人id
	        			for(String newId : newUserIdList) {
	        				if(!oldUserIdList.contains(newId)) {
	        					addList.add(newId);
	        				}
	        			}
	        			//获取已参加的人id
	        			for(String oldId : oldUserIdList) {
	        				if(newUserIdList.contains(oldId)) {
	        					noticeUpdateList.add(oldId);
	        				}
	        			}
	    				this.noticeInfoService.deleteNoticeInfoByApplyrecordId(id, corpId);
	    				this.noticeTurnoverService.deleteNoticeTurnover(id, corpId);
	        			this.signedInfoService.deleteSignedInfoByApplyrecordId(id, corpId);
					}
	    			//新建会议通知数据
	    			this.noticeInfoService.addNoticeInfo(newUserIdList, recordId, corpId);
	                //新建会议签到数据
	                if("1".equals(isSigned)) this.signedInfoService.addSignedInfo(newUserIdList, recordId, corpId);
	                //保存周期会议
	                if(applyRecord.getIsCycle() == 1) {
	                	List<ApplyRecord> arCycleList = this.applyRecordService.saveCycleMeeting(applyRecord, cyclelist);
	                	CycleMeetingThread cycThread = new CycleMeetingThread(arCycleList, newUserIdList, applyRecord.getId(), corpId, applyRecord.getIsSigned());
	                	cycThread.start();
	                }
				}
        		// 新建编辑会议发送会议申请通知
	            Map<String, Object> ds = new HashMap<>();
	            ds.put("applyRecordId", recordId);
	    		ds.put("meetingTitle", applyRecord.getName());
	    		ds.put("startTime", applyRecord.getStartTime());
	    		ds.put("boardroom", room == null ? "无" : room.getAddress());
	            String noticeUserId = applyRecord.getCreatedBy();
	            String sendUserName = "";
	            if(StringUtils.isNotEmpty(noticeUserId)){
	                Map<String, Object> userInfo = this.userApiService.getUser(noticeUserId, corpId,  "", TOKEN);
	                if(userInfo != null){
	                	sendUserName = StringUtils.null2String(userInfo.get("userName"));
	                }
	            }
	    		ds.put("userId", noticeUserId);
	    		ds.put("userName", sendUserName);
	    		ds.put("userOrg", applyRecord.getCreatedOrg());
	    		ds.put("type", "2");
	    		boolean mobilePush = false;
	            boolean emailPush = false;
	            boolean smsPublish = false;
				String mesgPush = applyRecord.getMessagePush();
				if(StringUtils.isNotEmpty(mesgPush) && mesgPush.contains("mobile")) mobilePush = true;
				if(StringUtils.isNotEmpty(mesgPush) && mesgPush.contains("email")) emailPush = true;
				if(StringUtils.isNotEmpty(mesgPush) && mesgPush.contains("sms")) smsPublish = true;
	        	if(isEdit) {
	        		//新增的参会人员发送邀请通知
	        		if(CollectionUtils.isNotEmpty(addList)) sendMessageToUser(emailPush, mobilePush, smsPublish, addList, ds, corpId, token, request);
	        		//已参会人员发送变更通知
	        		if(CollectionUtils.isNotEmpty(noticeUpdateList) && meetingInfoIsChange) {
	        			ds.put("type", "9");
	        			sendMessageToUser(emailPush, mobilePush, smsPublish, noticeUpdateList, ds, corpId, token, request);
	        		}
	        	}else {
	        		if(CollectionUtils.isNotEmpty(newUserIdList)) sendMessageToUser(emailPush, mobilePush, smsPublish, newUserIdList, ds, corpId, token, request);
	        	}
			}
		} catch (Exception e) {
			e.printStackTrace();
			return OperationResult.buildFailureResult("保存会议申请失败");
		}
		logger.info("保存会议申请信息结束");
		return OperationResult.buildSuccessResult("保存会议申请成功");
	}
	
	private ApplyRecord applyRecordCopy(ApplyRecord applyRecord) {
		ApplyRecord newEntity = new ApplyRecord();
		if(applyRecord != null) {
			String name = applyRecord.getName();
			if(name != null) newEntity.setName(name);
			String content = applyRecord.getContent();
			if(content != null) newEntity.setContent(content);
			String startTime = applyRecord.getStartTime();
			if(startTime != null) newEntity.setStartTime(startTime);
			String endTime = applyRecord.getEndTime();
			if(endTime != null) newEntity.setEndTime(endTime);
			newEntity.setIsSigned(applyRecord.getIsSigned());
			String signedTime = applyRecord.getSignedTime();
			if(signedTime != null) newEntity.setSignedTime(signedTime);
			String signedType = applyRecord.getSignedType();
			if(signedType != null) newEntity.setSignedType(signedType);
			String signedRange = applyRecord.getSignedRange();
			if(signedRange != null) newEntity.setSignedRange(signedRange);
			String remark = applyRecord.getRemark();
			if(remark != null) newEntity.setRemark(remark);
		}
		return newEntity;
	}

	/**
     * 发送消息通知
     * @param userIdList
     * @param ds
     * @param corpId
     * @param request
     */
    private void sendMessageToUser(boolean emailPush, boolean mobilePush, boolean smsPublish, List<String> userIdList, Map<String, Object> ds, String corpId, String token, HttpServletRequest request) {
    	StringBuffer ids = new StringBuffer();
		StringBuffer jsonIds = new StringBuffer("[");
		for(int i = 0; i < userIdList.size(); i++) {
			if(i == userIdList.size() - 1) {
				ids.append(userIdList.get(i));
				jsonIds.append("{\"10\":\"" + userIdList.get(i) + "\"}]");
			}else {
				ids.append(userIdList.get(i) + ",");
				jsonIds.append("{\"10\":\"" + userIdList.get(i) + "\"},");
			}
		}
		jsonIds.append("]");
		ds.put("userIds", ids.toString());
		ds.put("orgIds", "");
		if(!"".equals(ids.toString())) {
			this.meetingSendMsgUtils.sendMail(ds, emailPush, corpId, token);
			this.meetingSendMsgUtils.sendMsgToApp(ds, mobilePush, corpId, token, request);
			this.meetingSendMsgUtils.sendSMS(ds, smsPublish, corpId, token);
		}
		if(!"[]".equals(jsonIds.toString())) this.meetingSendMsgUtils.sendMessage(ds, jsonIds.toString(), corpId, token);
    }
		
	/**
     * 判断会议信息是否修改
     * @param newEntity
     * @param addrListJson
     * @param corpId
     * @return
     */
    private boolean isEntityChanged(ApplyRecord newEntity, String id, ApplyRecord oldEntity, String addrListJson, String corpId) {
    	List<SignedAddress> saOldList = this.signedAddressService.findByRecordId(newEntity.getId());
    	List<Map<String, String>> addrList = null;
		if(!"".equals(addrListJson)) {
			addrList = JsonUtils.readListValue(addrListJson);
		}
    	List<SignedAddress> saNewList = null;
    	if(CollectionUtils.isNotEmpty(addrList)) {
    		saNewList = new ArrayList<SignedAddress>();
    		for(Map<String, String> m : addrList) {
    			SignedAddress sa = new SignedAddress();
    			sa.setLongitude(m.get("lng"));
    			sa.setLatitude(m.get("lat"));
    			sa.setSignedAddress(m.get("address"));
    			saNewList.add(sa);
    		}
    	}
    	boolean sAddressIsSame = true;
    	if(CollectionUtils.isNotEmpty(saOldList) && CollectionUtils.isNotEmpty(saNewList)) {
    		if(!saOldList.equals(saNewList)) {
    			sAddressIsSame = false;
    		}
    	}else if((CollectionUtils.isEmpty(saOldList) && CollectionUtils.isNotEmpty(saNewList)) || 
    			(CollectionUtils.isNotEmpty(saOldList) && CollectionUtils.isEmpty(saNewList))){
    		sAddressIsSame = false;
    	}
    	if(oldEntity.equals(newEntity) && sAddressIsSame) return false;
    	else return true;
    }
		
	@ApiOperation(value = "流程提交后处理各个数据", notes = "保存会议状态和会议选人数据")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "id", value = "会议id", required = true, paramType = "body", dataType = "String"),
			@ApiImplicitParam(name = "status", value = "状态", required = true, paramType = "body", dataType = "String"),
			@ApiImplicitParam(name = "token", value = "", required = true, paramType = "body", dataType = "String"),
			@ApiImplicitParam(name = "userId", value = "", required = true, paramType = "body", dataType = "String"),
			@ApiImplicitParam(name = "corpId", value = "", required = true, paramType = "body", dataType = "String"),
			@ApiImplicitParam(name = "userName", value = "", required = true, paramType = "body", dataType = "String"),
			@ApiImplicitParam(name = "jsonStrEmceeUser", value = "主持人", required = true, paramType = "body", dataType = "String"),
			@ApiImplicitParam(name = "jsonStrMemoUser", value = "纪要员", required = true, paramType = "body", dataType = "String"),
			@ApiImplicitParam(name = "jsonStrAttendUser", value = "参会人员", required = true, paramType = "body", dataType = "String") })
	@RequestMapping(value = "/saveInfoAfterBpm", method = RequestMethod.POST)
	public OperationResult saveInfoAfterBpm(HttpServletRequest request, @RequestBody String jsonStr) {
		logger.info("保存会议信息开始");
		try {
			String id =  StringUtils.null2String(request.getParameter("id"));
			String nStatus =  StringUtils.null2String(request.getParameter("status"));
			ApplyRecord applyRecord = this.applyRecordDingService.findOne(id);
			if(applyRecord != null){
				//状态修改
				int status = applyRecord.getStatus();
				if(status != 1){
					if("4".equals(nStatus) || "6".equals(nStatus)){//提交
						applyRecord.setStatus(0);
					}else if("1".equals(nStatus)){//正常结束
						applyRecord.setStatus(1);
					}else if("5".equals(nStatus)){//保存到草稿箱
						applyRecord.setStatus(6);
					}
				}
				Map<String, Object> map = new HashMap<>();
				if(StringUtils.isNotEmpty(jsonStr)){
					map = JsonUtils.readValue(jsonStr);
				}
				// 主持人
				String emceeUserJsonStr = StringUtils.null2String(map.get("jsonStrEmceeUser"));
				String emceeUser = StringUtils.null2String(applyRecord.getEmceeUser());
				if ("".equals(emceeUser)) {
					emceeUser = UuidUtils.UUID();
					applyRecord.setEmceeUser(emceeUser);
				}
				this.popUserScopeUtilService.saveScopeData("oa_meeting_apply_record_scope", emceeUser, emceeUserJsonStr,
						"oa_meeting_apply_record", "emcee_user");
				// 纪要员
				String memoUserJsonStr = StringUtils.null2String(map.get("jsonStrMemoUser"));
				String memoUser = StringUtils.null2String(applyRecord.getMemoUser());
				if ("".equals(memoUser)) {
					memoUser = UuidUtils.UUID();
					applyRecord.setMemoUser(memoUser);
				}
				this.popUserScopeUtilService.saveScopeData("oa_meeting_apply_record_scope", memoUser, memoUserJsonStr,
						"oa_meeting_apply_record", "memo_user");
				// 参会人
				String attendUserJsonStr = StringUtils.null2String(map.get("jsonStrAttendUser"));
				String attendUser = StringUtils.null2String(applyRecord.getAttendUser());
				if ("".equals(attendUser)) {
					attendUser = UuidUtils.UUID();
					applyRecord.setAttendUser(attendUser);
				}
				this.popUserScopeUtilService.saveScopeData("oa_meeting_apply_record_scope", attendUser, attendUserJsonStr,
						"oa_meeting_apply_record", "attend_user");

				//改变提醒方式默认值
				int isNotice = applyRecord.getIsNotice();
				if(isNotice == 1){
					applyRecord.setNoticeType("2");
				}

				this.applyRecordDingService.save(applyRecord);
				//地址
				List<SignedAddress> list = this.signedAddressService.findByFkid(id);
				if(list!=null && list.size()>0){
					for(int i=0; i<list.size(); i++){
						SignedAddress address = list.get(i);
						if(address!=null && StringUtils.isEmpty(address.getApplyRecordId())){
							address.setApplyRecordId(address.getFkid());
						}
					}
					this.signedAddressService.save(list);
				}
				//推送
				if("1".equals(nStatus)){
					logger.info("会议参会邀请推送开始");
					String token = StringUtils.null2String(request.getParameter("token"));
					/*String userId = StringUtils.null2String(request.getParameter("userId"));
					String userName = StringUtils.null2String(request.getParameter("userName"));*/
					String corpId = StringUtils.null2String(request.getParameter("corpId"));
					this.applyRecordDingService.editApplyRecordInfo(applyRecord.getId(),"1","", "",token);
					//保存周期会议
		            if(applyRecord.getIsCycle() == 1) {
		            	List<String> newUserIdList = this.applyRecordService.getApplyRecordUserList(applyRecord, token);
		            	List<Map<String, String>> cyclelist = this.applyRecordService.getCycleDateList(applyRecord);
		            	List<ApplyRecord> arCycleList = this.applyRecordService.saveCycleMeeting(applyRecord, cyclelist);
		            	CycleMeetingThread cycThread = new CycleMeetingThread(arCycleList, newUserIdList, applyRecord.getId(), corpId, applyRecord.getIsSigned());
		            	cycThread.start();
		            }
					BoardroomSet room = null;
					if(StringUtils.isNotEmpty(applyRecord.getBoardroomId())) {
						room = this.boardroomSetService.findOne(applyRecord.getBoardroomId());
					}
					// 新建编辑会议发送会议申请通知
					int nStauts = applyRecord.getStatus();
					String userIds = "", orgIds = "", jsonIds = "[";
					Map<String, Object> ds = new HashMap<>();
					ds.put("applyRecordId", id);
					ds.put("meetingTitle", applyRecord.getName());
					ds.put("startTime", applyRecord.getStartTime());
					ds.put("boardroom", room == null ? "无":room.getAddress());
					String noticeUserId = applyRecord.getCreatedBy();
					String userName = "";
					if(StringUtils.isNotEmpty(noticeUserId)){
						Map<String, Object> userInfo = this.userApiService.getUser(noticeUserId, corpId,  "", token);
						if(userInfo != null){
							userName = StringUtils.null2String(userInfo.get("userName"));
						}
					}
					ds.put("userId", noticeUserId);
					ds.put("userName", userName);
					ds.put("userOrg", applyRecord.getCreatedOrg());
					if(nStauts == 1){
						ds.put("type", "2");
						List<String> userIdList = this.applyRecordService.getApplyRecordUserList(applyRecord, token);
						if(CollectionUtils.isNotEmpty(userIdList)){
	        				StringBuffer ids = new StringBuffer();
	        				StringBuffer jsonIdsBuffer = new StringBuffer("[");
	        				for(int i = 0; i < userIdList.size(); i++) {
	        					if(i == userIdList.size() - 1) {
	        						ids.append(userIdList.get(i));
	        						jsonIdsBuffer.append("{\"10\":\"" + userIdList.get(i) + "\"}]");
	        					}else {
	        						ids.append(userIdList.get(i) + ",");
	        						jsonIdsBuffer.append("{\"10\":\"" + userIdList.get(i) + "\"},");
	        					}
	        				}
	        				jsonIdsBuffer.append("]");
	        				userIds = ids.toString();
	        				jsonIds = jsonIdsBuffer.toString();
						}
					}
					if(!StringUtils.isEmpty(userIds)){
						boolean mobilePush = false;
			            boolean emailPush = false;
			            boolean smsPublish = false;
						String mesgPush = applyRecord.getMessagePush();
						if(StringUtils.isNotEmpty(mesgPush) && mesgPush.contains("mobile")) mobilePush = true;
						if(StringUtils.isNotEmpty(mesgPush) && mesgPush.contains("email")) emailPush = true;
						if(StringUtils.isNotEmpty(mesgPush) && mesgPush.contains("sms")) smsPublish = true;
						ds.put("userIds", userIds);
						ds.put("orgIds", orgIds);
						this.meetingSendMsgUtils.sendMail(ds, emailPush, corpId, token);
						this.meetingSendMsgUtils.sendMsgToApp(ds, mobilePush, corpId, token, request);
						this.meetingSendMsgUtils.sendSMS(ds, smsPublish, corpId, token);
					}
					if(StringUtils.isNotEmpty(jsonIds) || !"[]".equals(jsonIds)){
						this.meetingSendMsgUtils.sendMessage(ds, jsonIds, corpId, token);
					}
					logger.info("会议参会邀请推送结束");
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			return OperationResult.buildFailureResult("保存会议失败");
		}
		logger.info("保存会议信息结束");
		return OperationResult.buildSuccessResult("保存会议成功");
	}
	
	/**
	 * 会议参会详细
	 */
	@ApiOperation(value = "会议参会详细", notes = "查询会议用户参会详细信息列表数据")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "id", value = "会议id", required = true, paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "type", value = "0:未反馈； 1:确认参会； 2:已请假；3:未签到；4:已签到；", required = true, paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "page", value = "当前显示页数", required = true, paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "pageSize", value = "一页显示数", required = true, paramType = "query", dataType = "String") })
	@RequestMapping(value = "/approvalNoticeInfoSetList", method = RequestMethod.GET, produces = {
			"application/json; charset=UTF-8" })
	public OperationResult getApprovalNoticeInfoSetList(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			// 当前页
			String currentPage = request.getParameter("page");
			// 一页显示条数
			String pageSize = request.getParameter("pageSize");
			String id = request.getParameter("id");
			String type = request.getParameter("type");
			List<Map> list = new ArrayList<>();
			// 查询会议参会详细
			if("0".equals(type) || "1".equals(type) || "2".equals(type)) {
				list = this.applyRecordDingService.getApplyRecordNoticeList(request, currentPage, pageSize, id, type,
						map);
			} else if ("3".equals(type) || "4".equals(type)) {
				list = this.applyRecordDingService.getApplyRecordSigned(request, currentPage, pageSize, id, type, map);
			}
			map.put("data", list);
			map.put("currentPage", Integer.parseInt(currentPage));
		} catch (Exception e) {
			return OperationResult.buildFailureResult("获取失败");
		}
		return OperationResult.buildSuccessResult(map);
	}

	/**
	 * 流程结束后是否可发起会议或取消预约
	 */
	@ApiOperation(value = "是否可发起会议或取消预约", notes = "预约会议室流程结束后判断是否可发起会议或是否可取消预约会议室")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "id", value = "会议id", required = true, paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "corpId", value = "企业id", required = true, paramType = "query", dataType = "String") })
	@RequestMapping(value = "/canCancelMeeting", method = RequestMethod.GET, produces = {
			"application/json; charset=UTF-8" })
	public OperationResult canCancelMeeting(HttpServletRequest request) {
		String result = "0";//不可取消会议
		try {
			String corpId = request.getParameter("corpId");
			//选择日期
			String id = ValidateUtils.filter(request.getParameter("id"));

			if (StringUtils.isNotEmpty(id)) {
				ApplyRecord applyRecord = this.applyRecordDingService.findOne(id);
				if(applyRecord != null){
					int status = applyRecord.getStatus();
					if (status == 1) {
						result = "1"; //可取消会议
					}
				}
			}
		} catch (Exception e) {
			return OperationResult.buildFailureResult("获取失败");
		}
		return OperationResult.buildSuccessResult(result);
	}

	/**
	 * 生成签到二维码
	 */
	@ApiOperation(value = "签到二维码", notes = "生成签到二维码")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "id", value = "会议id", required = true, paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "corpId", value = "企业id", required = true, paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "token", value = "token", required = true, paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "url", value = "ip", required = true, paramType = "query", dataType = "String") })
	@RequestMapping(value = "/getQrcodeAttachment", method = RequestMethod.GET, produces = {
	"application/json; charset=UTF-8" })
	public OperationResult getQrcodeAttachment(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			String id = request.getParameter("id");
			String corpId = request.getParameter("corpId");
			String token = request.getParameter("token");
			String url = request.getParameter("url");
			ApplyRecord record = this.applyRecordDingService.findOne(id);
			String attachId = record.getQrcodeAttach();
            Urlconvert urlconvert = new Urlconvert();
            urlconvert.setDingUrl(this.getMessageUrl("0", id, corpId, token));
            urlconvert.setWxUrl(this.getMessageUrl("1", id, corpId, token));
            urlconvert.setMhUrl(this.getMessageUrl("2", id, corpId, token));
            urlconvert = this.urlconvertService.save(urlconvert);
            String qrUrl = url+"/api/meeting/murl?id="+urlconvert.getId();
            attachId = this.createQrCode(request, qrUrl, token);
            record.setQrcodeAttach(attachId);
            this.applyRecordDingService.save(record);
			map.put("attachments", attachId);
//			if(StringUtils.isNotEmpty(attachId)){
//        		List<Map<String, String>> images = this.attachmentUtilsService.getAttachmentByIds(attachId, corpId, token);
//        		if(images!=null && images.size()>0){
//        			Map<String, String> image = images.get(0);
//        			map.put("image", image.get("imageUrl"));
//        		}
//        	}
		} catch (Exception e) {
			e.printStackTrace();
			return OperationResult.buildFailureResult("获取失败");
		}
		return OperationResult.buildSuccessResult(map);
	}
	
	/**
	 * 获取各个平台签到路径
	 * @param type 0:钉钉 1:企业微信 2:移动平台
	 * @param id
	 * @param webUrl
	 * @param corpId
	 * @param token
	 * @return
	 */
	private String getMessageUrl(String type, String id, String corpId, String token) {
		String messageUrl = "";
		String appId = "";
		String corpReally = "";
		if("2".equals(type)) {
			messageUrl = "/static/officeding/meeting/dist/index.html?dd_nav_bgcolor=FF5E97F6#/meeting/qrcodeSign/" + id;
		}else {
			Map<String,Object> mpMap = mobileParamdataService.getParamDataMap(corpId, "meeting", type, token);
	    	if(MapUtils.isNotEmpty(mpMap)) {
	    		String code = String.valueOf(mpMap.get("code"));
	    		if(code.equals("0")) {//获取成功
	    			corpReally = String.valueOf(mpMap.get("corpId"));
	    			appId = String.valueOf(mpMap.get("agentId"));
	    		}
	    	}
			messageUrl = "/static/officeding/meeting/dist/index.html"
	                + "?appid=" + appId
	                + "&corpid=" + corpReally
	                + "&dd_nav_bgcolor=FF5E97F6#/meeting/qrcodeSign"
	                + "/" + id;
		}
		return messageUrl;
	}
	
	/**
     * 生成二维码图片
     *
     * @param content
     */
    public String createQrCode(HttpServletRequest request, String content, String token) {
    	String attId = "";
    	try {
    		//计算二维码图片的高宽比
            // API文档规定计算图片宽高的方式 ，v是本次测试的版本号
            int v = 7;
            int width = 67 + 12 * (v - 1);
            int height = 67 + 12 * (v - 1);
        	Qrcode qrcode = new Qrcode();  
            qrcode.setQrcodeErrorCorrect('M');//纠错等级（分为L、M、H三个等级）  
            qrcode.setQrcodeEncodeMode('B');//N代表数字，A代表a-Z，B代表其它字符  
            qrcode.setQrcodeVersion(v);//版本    
            BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);  
            //绘图  
            Graphics2D gs = bufferedImage.createGraphics();  
            gs.setBackground(Color.WHITE);  
            gs.setColor(Color.BLACK);  
            gs.clearRect(0, 0, width, height);//清除下画板内容  
              
            //设置下偏移量,如果不加偏移量，有时会导致出错。  
            int pixoff = 2; 
            //String qrData="www.baidu.com";
              
            byte[] d = content.getBytes("utf-8");;  
            if(d.length > 0){  
                boolean[][] s = qrcode.calQrcode(d);
                for(int i=0;i<s.length;i++){  
                    for(int j=0;j<s.length;j++){  
                        if(s[j][i]){  
                            gs.fillRect(j*3+pixoff, i*3+pixoff, 3, 3);  
                        }  
                    }  
                }  
            }  
            gs.dispose();  
            bufferedImage.flush();  

            // 生成二维码QRCode图片
            String pathTime=DateUtils.formatDate(new Date(), "yyyyMMddHHmmssSSS");
		    String path = org.ezplatform.util.http.WebUtils.getWebRealPath(request)+"attachment\\meetingUpload\\"+pathTime+"\\" ;
			File file = new File(path);
			if(!file.exists()){//判断文件目录是否存在    
				file.mkdirs();  
            }  
			String filePath = path + "qrcode" + pathTime + ".png";
			file = new File(filePath);
            // 生成的图片在D盘下，名为 qrCode.png
			ImageIO.write(bufferedImage, "png", file);
			
			
			
            List<Map<String,Object>> list =(List<Map<String, Object>>) this.attachmentUtilsService.upload("meeting",file,token);
    		if(null!=list && list.size()>0){
    			list.get(0).get("id");
    			if(StringUtils.isNotBlank(attId)){
    				attId+="|"+list.get(0).get("id");
    			}else{
    				attId=(String) list.get(0).get("id");
    			}
    		}
    		file.delete();
    		File f = new File(path);
    		if(f.exists()){
    			f.delete();
    		}
        } catch (Exception e) {
            e.printStackTrace();
        }
    	return attId;
    }
	
	/**
	 * 会议参会详细
	 */
	@ApiOperation(value = "会议参会详细", notes = "查询会议用户参会详细信息列表数据")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "corpId", value = "企业id", required = true, paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "token", value = "token", required = true, paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "id", value = "会议id", required = true, paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "type", value = "0:未反馈； 1:确认参会； 2:已请假；3:未签到；4:已签到；", required = true, paramType = "query", dataType = "String") })
	@RequestMapping(value = "/getAllApprovalUserIds", method = RequestMethod.GET, produces = {
	"application/json; charset=UTF-8" })
	public OperationResult getAllApprovalUserIds(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			String id = request.getParameter("id");
			String type = request.getParameter("type");
			String corpId = request.getParameter("corpId");
			String token = request.getParameter("token");
			List<Map> list = new ArrayList<>();
			List<String> data = new ArrayList<>();
			String userIds = "";
			if("end".equals(type)){
				List<Object[]> userList = this.signedInfoService.getSignedUserList(id, 0);
				List<Map<String, Object>> users = new ArrayList<>();
				for(int i=0;i<userList.size();i++){
					Object[] objs = userList.get(i);
					Map<String, Object> map2 = new HashMap<>();
					map2.put("value", objs[0]);
					map2.put("text", objs[1]);
					map2.put("checked", false);
					map2.put("disable", false);
					users.add(map2);
				}
				map.put("userList", users);
			}else{
				// 查询会议参会详细
				if ("0".equals(type)) {
					list = this.applyRecordDingService.getApplyRecordNoticeList(request, "", "-2", id, type,
							map);
					for (Map<String, Object> map2 : list) {
						String userId = StringUtils.null2String(map2.get("userId"));
						if(StringUtils.isNotEmpty(userId)){
							userIds += userId + ",";
						}
					}
				} else if ("3".equals(type)) {
					list = this.applyRecordDingService.getApplyRecordSigned(request, "", "-2", id, type, map);
					for (Map<String, Object> map2 : list) {
						String signedUserId = StringUtils.null2String(map2.get("signedUserId"));
						if(StringUtils.isNotEmpty(signedUserId)){
							userIds += signedUserId + ",";
						}
					}
				}
				if(StringUtils.isNotEmpty(userIds) && userIds.charAt(userIds.length()-1) == ',') {
					userIds = userIds.substring(0, userIds.length() - 1);
				}
				//data = this.userApiService.getUserIdBySysOrThird(userIds, "1", "DD", corpId, token);
				map.put("data", userIds);
			}
		} catch (Exception e) {
			return OperationResult.buildFailureResult("获取失败");
		}
		return OperationResult.buildSuccessResult(map);
	}
	
	/**
	 * 会议签到信息
	 */
	@ApiOperation(value = "会议签到信息", notes = "查询当前用户签到信息和会议的签到设置")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "applyRecordId", value = "会议id", required = true, paramType = "query", dataType = "String") })
	@RequestMapping(value = "/getSignedInfo", method = RequestMethod.GET, produces = {
	"application/json; charset=UTF-8" })
	public OperationResult getSignedInfo(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			String applyRecordId = request.getParameter("applyRecordId");
			String userId = request.getParameter("userId");
			SignedInfo signedInfo = this.signedInfoService.getSignedInfo(userId, applyRecordId);
			map.put("singedInfo", signedInfo);
			ApplyRecord record = this.applyRecordDingService.findOne(applyRecordId);
			map.put("record", record);
			List<SignedAddress> list = this.signedAddressService.findByRecordId(applyRecordId);
			map.put("addressList", list);
		} catch (Exception e) {
			return OperationResult.buildFailureResult("获取失败");
		}
		return OperationResult.buildSuccessResult(map);
	}
	
	private Map<String, String> transformUserScopePlatform2Dd(String fieldDataValue, String table, String fieldData, String corpId, String token){
        String ids = "", jsonIds = "";
		Map<String, String> result = new HashMap<>();
        String scopeTypeStr = this.popUserScopeUtilService.getScopeTypeValue("oa_meeting_apply_record_scope", table, fieldData, StringUtils.null2String(fieldDataValue));
        String[] scopeTypeArray = scopeTypeStr.split(",");
        if(scopeTypeArray != null && scopeTypeArray.length>0) {
        	List<String> l = new ArrayList<>();
            for (int i = 0; i < scopeTypeArray.length; i++) {
                String[] info = scopeTypeArray[i].split("SCOPE");
                if (info.length > 1){
                	String id  = info[1];
                	String type  = info[0];
                	List<String> u = new ArrayList<>();
                	if("user".equals(type)){
						jsonIds +="{\"10\":\""+id+"\"},";
						l.add(id);
//                		u = this.userApiService.getUserIdBySysOrThird(id, "1", "DD", corpId, token);
                	}
//                    if(u!=null && u.size()>0){
//                    	l.addAll(u);
//                    }
                }
            }
            if(l!=null && l.size()>0){
            	for(int i=0; i<l.size(); i++){
            		String thirdId = l.get(i);
            		if(StringUtils.isNotEmpty(thirdId)){
            			ids += thirdId + ",";
            		}
            	}
            }
        }
		result.put("jsonIds", jsonIds);
		result.put("ids", ids);
        return result;
    }

	private Map<String, String> transformUOScopePlatform2Dd(String fieldDataValue, String table, String fieldData, String corpId, String token){
		Map<String, String> map = new HashMap<>();
		String ids = "", orgIds = "", jsonIds = "";
        String scopeTypeStr = this.popUserScopeUtilService.getScopeTypeValue("oa_meeting_apply_record_scope", table, fieldData, StringUtils.null2String(fieldDataValue));
        String[] scopeTypeArray = scopeTypeStr.split(",");
        if(scopeTypeArray != null && scopeTypeArray.length>0) {
        	List<String> l = new ArrayList<>();
        	List<String> o = new ArrayList<>();
            for (int i = 0; i < scopeTypeArray.length; i++) {
                String[] info = scopeTypeArray[i].split("SCOPE");
                if (info.length > 1){
                	String id  = info[1];
                	String type  = info[0];
                	if("user".equals(type)){
						jsonIds +="{\"10\":\""+id+"\"},";
						l.add(id);
//                		List<String> u = this.userApiService.getUserIdBySysOrThird(id, "1", "DD", corpId, token);
//                		if(u!=null && u.size()>0){
//                        	l.addAll(u);
//                        }
                	}else if("org".equals(type)){
						jsonIds +="{\"20\":\""+id+"\"},";
						o.add(id);
//                		List<String> u = this.orgApiService.getOrgIdOrThirdUid(id, "1", "DD", corpId, token);
//                		if(u!=null && u.size()>0){
//                			for(int j=0; j<u.size(); j++){
//                				if("1".equals(u.get(j))){
//                					Map<String, Object> topOrgInfo = this.orgApiService.getPopuOrgChildInfo(id,"user", "","", "", corpId, token);
//                					List<Map<String, Object>> userList = (List<Map<String, Object>>)topOrgInfo.get("userList");
//									List<Map<String, Object>> orgList = (List<Map<String, Object>>)topOrgInfo.get("orgList");
//									if(userList!=null && userList.size()>0){
//										for(int k=0; k<userList.size(); k++){
//											Map<String, Object> map1 = userList.get(k);
//											String ddUId = StringUtils.null2String(map1.get("ddUId"));
//											if(StringUtils.isNotEmpty(ddUId)){
//												l.add(ddUId);
//											}
//										}
//									}
//									if(orgList!=null && orgList.size()>0){
//										for(int k=0; k<orgList.size(); k++){
//											Map<String, Object> map1 = orgList.get(k);
//											String ddUId = StringUtils.null2String(map1.get("ddUId"));
//											if(StringUtils.isNotEmpty(ddUId)){
//												o.add(ddUId);
//											}
//										}
//									}
//                				}else{
//									o.add(u.get(j));
//								}
//							}
//                        }
                	}
                }
            }
            if(l!=null && l.size()>0){
            	for(int i=0; i<l.size(); i++){
            		String thirdId = l.get(i);
            		if(StringUtils.isNotEmpty(thirdId)){
            			ids += thirdId + ",";
            		}
            	}
            }

            if(o!=null && o.size()>0){
            	for(int i=0; i<o.size(); i++){
            		String thirdId = o.get(i);
            		if(StringUtils.isNotEmpty(thirdId)){
            			orgIds += thirdId + ",";
            		}
            	}
            }
        }
		map.put("jsonIds", jsonIds);
        map.put("userIds", ids);map.put("orgIds", orgIds);
        return map;
    }

	/**
	 * 修改会议状态
	 */
	@ApiOperation(value = "修改会议状态", notes = "同意、驳回、取消会议申请")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "token", value = "token", required = true, paramType = "body", dataType = "String"),
    	@ApiImplicitParam(name = "corpId", value = "企业id", required = true, paramType = "body", dataType = "String"),
        @ApiImplicitParam(name = "id", value = "会议id", required = true, paramType = "body", dataType = "String"),
        @ApiImplicitParam(name = "status", value = "1:同意会议 2:驳回会议  3:取消会议", required = true, paramType = "body", dataType = "String"), 
        @ApiImplicitParam(name = "noticeInfoId", value = "会议通知ID  必填（1:同意会议 2:驳回会议） 不必填（3:取消会议） ", required =false , paramType = "body", dataType = "String"), 
        @ApiImplicitParam(name = "reason", value = "会议取消、驳回原因", required =false , paramType = "body", dataType = "String"), 
    })
    @RequestMapping(value = "/editApplyRecordInfo", method = RequestMethod.POST)
    public OperationResult editApplyRecordInfo(HttpServletRequest request) {
        logger.debug("保存会议状态开始");
        try {
            String id =  request.getParameter("id");
            String nStatus = request.getParameter("status");
            String reason =  request.getParameter("reason");
            String token = request.getParameter("token");
            String corpId = request.getParameter("corpId");
            
            ApplyRecord applyRecord = this.applyRecordDingService.findOne(id);
            int status = applyRecord.getStatus();
            if(status!=0 && ("1".equals(nStatus)||"2".equals(nStatus))){
            	return OperationResult.buildFailureResult("该会议已审批");
            }
            if(status == 3){
            	return OperationResult.buildFailureResult("该会议已取消");
            }
            if("3".equals(nStatus) && status==1){
                List<String> taskIds = meetingTaskInfoService.findTaskInfoIdsByApplyRecordIds(id);
                //取消会议前删除会议相关任务
                this.meetingTaskInfoService.deleteByRecordId(id);
        		//删除相关会议消息
            	this.meetingSendMsgUtils.deleteMessage(taskIds, corpId, token);
            	//释放会议室
            	if(StringUtils.isNotBlank(applyRecord.getBoardroomId())) {
            		this.applyRecordService.saveNewBoardRoomApply(applyRecord);
            	}
            }
            this.applyRecordDingService.editApplyRecordInfo(id,nStatus,reason,"changeStatus",token);
            BoardroomSet room = null;
            if(StringUtils.isNotBlank(applyRecord.getBoardroomId())) {
            	room = this.boardroomSetService.findOne(applyRecord.getBoardroomId());
            }
            String isApprove = StringUtils.null2String(room.getIsApprove());
            if(("1".equals(nStatus)&& status==0) || "3".equals(nStatus) ){
            	Map<String, Object> ds = new HashMap<>();
            	if("1".equals(nStatus)){
            		ds.put("type", "2");
            	}else{
            		ds.put("type", "3");
            	}
            	ds.put("reason", reason);
    			ds.put("applyRecordId", applyRecord.getId());
    			ds.put("meetingTitle", applyRecord.getName());
    			ds.put("startTime", applyRecord.getStartTime());
    			ds.put("boardroom", room.getAddress());
    			String noticeUserId = applyRecord.getCreatedBy();
    			ds.put("userId", noticeUserId);
    			Map<String, Object> user =  this.userApiService.getUser(noticeUserId, corpId, "", token);
    			String userName = StringUtils.null2String(user.get("userName"));
    			ds.put("userName", userName);
    			ds.put("userOrg", applyRecord.getCreatedOrg());
//    			String ids = "", orgIds = "", jsonIds = "[";
//    			if("3".equals(nStatus) && status==0 && !"0".equals(isApprove)){//取消未审批的会议(会议室需审批)
//    				String adminScope = room.getAdminUserScope();
//					Map<String, String> idsMap = new HashMap<>();
//    				idsMap = this.transformUserScopePlatform2Dd(adminScope, "oa_meeting_boardroom_set", "admin_user_scope", corpId, TOKEN);
//    				ids = idsMap.get("ids");
//    				jsonIds = idsMap.get("jsonIds");
//    			}else{
//    				String emceeUser = applyRecord.getEmceeUser();
//					Map<String, String> idsMap1 = new HashMap<>();
//        			idsMap1 = this.transformUserScopePlatform2Dd(emceeUser, "oa_meeting_apply_record", "emcee_user", corpId, token);
//        			ids += idsMap1.get("ids");
//        			jsonIds += idsMap1.get("jsonIds");
//        			String memoUser = applyRecord.getMemoUser();
//					Map<String, String> idsMap2 = new HashMap<>();
//        			idsMap2 = this.transformUserScopePlatform2Dd(memoUser, "oa_meeting_apply_record", "memo_user", corpId, token);
//        			ids += idsMap2.get("ids");
//        			jsonIds += idsMap2.get("jsonIds");
//        			String attendUser = applyRecord.getAttendUser();
//        			Map<String, String> map = new HashMap<>();
//    				map = this.transformUOScopePlatform2Dd(attendUser, "oa_meeting_apply_record", "attend_user", corpId, token);
//    				ids += map.get("userIds");
//    				orgIds += map.get("orgIds");
//    				jsonIds += map.get("jsonIds");
//        		}
    			
    			List<String> userIdList = this.applyRecordService.getApplyRecordUserList(applyRecord, token);
    			if(CollectionUtils.isNotEmpty(userIdList)){
    				StringBuffer ids = new StringBuffer();
    				StringBuffer jsonIds = new StringBuffer("[");
    				for(int i = 0; i < userIdList.size(); i++) {
    					if(i == userIdList.size() - 1) {
    						ids.append(userIdList.get(i));
    						jsonIds.append("{\"10\":\"" + userIdList.get(i) + "\"}]");
    					}else {
    						ids.append(userIdList.get(i) + ",");
    						jsonIds.append("{\"10\":\"" + userIdList.get(i) + "\"},");
    					}
    				}
    				jsonIds.append("]");
	    			if(!StringUtils.isEmpty(ids.toString())){
	    				boolean mobilePush = false;
	    	            boolean emailPush = false;
	    	            boolean smsPublish = false;
	    				String mesgPush = applyRecord.getMessagePush();
	    				if(StringUtils.isNotEmpty(mesgPush) && mesgPush.contains("mobile")) mobilePush = true;
	    				if(StringUtils.isNotEmpty(mesgPush) && mesgPush.contains("email")) emailPush = true;
	    				if(StringUtils.isNotEmpty(mesgPush) && mesgPush.contains("sms")) smsPublish = true;
	    				ds.put("userIds", ids);
	    				ds.put("orgIds", "");
	    				this.meetingSendMsgUtils.sendMail(ds, emailPush, corpId, TOKEN);
	    				this.meetingSendMsgUtils.sendMsgToApp(ds, mobilePush, corpId, token, request);
						this.meetingSendMsgUtils.sendSMS(ds, smsPublish, corpId, token);
	    			}
					if(!"[]".equals(jsonIds.toString())){
						this.meetingSendMsgUtils.sendMessage(ds, jsonIds.toString(), corpId, token);
					}
    			}
            }
        } catch (Exception e) {
           e.printStackTrace();
           return OperationResult.buildFailureResult("保存会议状态状态失败");
        }
        logger.debug("保存会议状态状态结束");
        return OperationResult.buildSuccessResult("保存会议状态状态成功");
    }
	
	/**
	 * 修改会议状态
	 */
	@ApiOperation(value = "修改会议状态", notes = "释放或占用会议室资源")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "applyRecordId", value = "会议id", required = true, paramType = "body", dataType = "String"),
        @ApiImplicitParam(name = "type", value = "", required = true, paramType = "body", dataType = "String"),
        @ApiImplicitParam(name = "token", value = "", required = true, paramType = "body", dataType = "String"),
        @ApiImplicitParam(name = "userId", value = "", required = true, paramType = "body", dataType = "String"),
        @ApiImplicitParam(name = "corpId", value = "", required = true, paramType = "body", dataType = "String"),
        @ApiImplicitParam(name = "userName", value = "", required = true, paramType = "body", dataType = "String"),
        @ApiImplicitParam(name = "status", value = "1-占用会议室资源，其他-释放会议室资源", required = true, paramType = "body", dataType = "String")
    })
    @RequestMapping(value = "/changeByStatusBpm", method = RequestMethod.POST)
    public OperationResult changeByStatusBpm(HttpServletRequest request) {
        logger.debug("保存会议状态开始");
		OperationResult result = null;
        try {
        	String id = StringUtils.null2String(request.getParameter("applyRecordId"));
			if(StringUtils.isNotEmpty(id)){
				String nStatus = ValidateUtils.filter(request.getParameter("status"));
				ApplyRecord entity = this.applyRecordDingService.findOne(id);
				int status = entity.getStatus();
				String type = StringUtils.null2String(request.getParameter("type"));
				int changeStatus = status;
				if("cancel".equals(type)){//流程结束后取消会议室预约，释放会议室资源
					if (status == 0) {
						changeStatus = -1;
					}else if(status == -1){
						return OperationResult.buildFailureResult("已取消预约");
					}else{
						return OperationResult.buildFailureResult("已发起会议，不可取消预约");
					}
				}else{
					if("1".equals(nStatus)){//正常结束
						changeStatus = 1;
					}else if("0".equals(nStatus)){//驳回到发起人
						changeStatus = 2;
					}else if("3".equals(nStatus) || "2".equals(nStatus)){//发起人撤销或非正常结束
						changeStatus = -1;
					}else if("4".equals(nStatus)){//表单提交
						changeStatus = 0;
					}else if("7".equals(nStatus)){//结束
						String startTime = entity.getStartTime();
						SimpleDateFormat sf  = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
						Date _startTime = sf.parse(startTime + ":00");
						Date now = new Date();
						if(_startTime.getTime() < now.getTime()) changeStatus = -1;
						else changeStatus = 1;
					}
				}
				List<String> ids = new ArrayList<>();
				ids.add(id);
				this.applyRecordDingService.changeStatusById(changeStatus, ids);
				if(changeStatus == 1){//会议流程正常结束，会议为未召开状态，发送推送消息
					String token = StringUtils.null2String(request.getParameter("token"));
					/*String userId = StringUtils.null2String(request.getParameter("userId"));
					String userName = StringUtils.null2String(request.getParameter("userName"));*/
					String corpId = StringUtils.null2String(request.getParameter("corpId"));
					this.applyRecordDingService.editApplyRecordInfo(entity.getId(),"1","", "",token);
					BoardroomSet room = null;
					if(StringUtils.isNotEmpty(entity.getBoardroomId())) {
						room = this.boardroomSetService.findOne(entity.getBoardroomId());
					}
					// 新建编辑会议发送会议申请通知
					int nStauts = entity.getStatus();
					String userIds = "", orgIds = "", jsonIds = "[";
					Map<String, Object> ds = new HashMap<>();
					ds.put("applyRecordId", id);
					ds.put("meetingTitle", entity.getName());
					ds.put("startTime", entity.getStartTime());
					ds.put("boardroom", room == null ? "无":room.getAddress());
					String noticeUserId = entity.getCreatedBy();
					String userName = "";
					if(StringUtils.isNotEmpty(noticeUserId)){
						Map<String, Object> userInfo = this.userApiService.getUser(noticeUserId, corpId,  "", token);
						if(userInfo != null){
							userName = StringUtils.null2String(userInfo.get("userName"));
						}
					}
					ds.put("userId", noticeUserId);
					ds.put("userName", userName);
					ds.put("userOrg", entity.getCreatedOrg());
					if(nStauts == 1){
						ds.put("type", "2");
//						Map<String, String> idsMap1 = new HashMap<>();
//						idsMap1 = this.transformUserScopePlatform2Dd(entity.getEmceeUser(), "oa_meeting_apply_record", "emcee_user", corpId, TOKEN);
//						userIds += idsMap1.get("ids");
//						jsonIds += idsMap1.get("jsonIds");
//						Map<String, String> idsMap2 = new HashMap<>();
//						idsMap2 = this.transformUserScopePlatform2Dd(entity.getMemoUser(), "oa_meeting_apply_record", "memo_user", corpId, TOKEN);
//						userIds += idsMap2.get("ids");
//						jsonIds += idsMap2.get("jsonIds");
//						Map<String, String> uoMap = new HashMap<>();
//						uoMap = this.transformUOScopePlatform2Dd(entity.getAttendUser(), "oa_meeting_apply_record", "attend_user", corpId, TOKEN);
//						userIds += uoMap.get("userIds");
//						orgIds += uoMap.get("orgIds");
//						jsonIds += uoMap.get("jsonIds");
						
						List<String> userIdList = this.applyRecordService.getApplyRecordUserList(entity, token);
						if(CollectionUtils.isNotEmpty(userIdList)){
	        				StringBuffer idsBuffer = new StringBuffer();
	        				StringBuffer jsonIdsBuffer = new StringBuffer("[");
	        				for(int i = 0; i < userIdList.size(); i++) {
	        					if(i == userIdList.size() - 1) {
	        						idsBuffer.append(userIdList.get(i));
	        						jsonIdsBuffer.append("{\"10\":\"" + userIdList.get(i) + "\"}]");
	        					}else {
	        						idsBuffer.append(userIdList.get(i) + ",");
	        						jsonIdsBuffer.append("{\"10\":\"" + userIdList.get(i) + "\"},");
	        					}
	        				}
	        				jsonIdsBuffer.append("]");
	        				userIds = idsBuffer.toString();
	        				jsonIds = jsonIdsBuffer.toString();
						}
					}
					
					if(!StringUtils.isEmpty(userIds)){
						boolean mobilePush = false;
			            boolean emailPush = false;
			            boolean smsPublish = false;
						String mesgPush = entity.getMessagePush();
						if(StringUtils.isNotEmpty(mesgPush) && mesgPush.contains("mobile")) mobilePush = true;
						if(StringUtils.isNotEmpty(mesgPush) && mesgPush.contains("email")) emailPush = true;
						if(StringUtils.isNotEmpty(mesgPush) && mesgPush.contains("sms")) smsPublish = true;
						ds.put("userIds", userIds);
						ds.put("orgIds", orgIds);
						this.meetingSendMsgUtils.sendMail(ds, emailPush, corpId, TOKEN);
						this.meetingSendMsgUtils.sendMsgToApp(ds, mobilePush, corpId, token, request);
    					this.meetingSendMsgUtils.sendSMS(ds, smsPublish, corpId, token);
					}
					if(StringUtils.isNotEmpty(jsonIds)){
						this.meetingSendMsgUtils.sendMessage(ds, jsonIds, corpId, token);
					}
				}
			}
        } catch (Exception e) {
           e.printStackTrace();
			return  OperationResult.buildFailureResult("保存会议状态状态失败");
        }
        logger.debug("保存会议状态状态结束");
        return  OperationResult.buildSuccessResult("保存会议状态状态成功");
    }

	/**
     * 删除会议
     */
    @ApiOperation(value = "删除会议", notes = "删除会议申请")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "会议id", required = true, paramType = "body", dataType = "String"),
        @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "body", dataType = "String") ,
		@ApiImplicitParam(name = "corpId", value = "corpId", required = true, paramType = "body", dataType = "String") })
    @RequestMapping(value = "/deletApplyRecordInfo", method = RequestMethod.POST)
    public OperationResult deletApplyRecordInfo(HttpServletRequest request) {
        logger.debug("删除会议开始");
        try {
            String id = StringUtils.null2String(request.getParameter("id"));
    		String token = StringUtils.null2String(request.getParameter("token"));
    		String corpId = StringUtils.null2String(request.getParameter("corpId"));
    		List<String> dataIds = new ArrayList<String>();
            //删除关联的scope
        	List<String> attendUser = new ArrayList<>();
        	List<String> emceeUser = new ArrayList<>();
        	List<String> memoUser = new ArrayList<>();
        	ApplyRecord record = this.applyRecordDingService.findOne(id);
        	if(record == null) return OperationResult.buildSuccessResult("删除会议成功");
        	dataIds.add(id);
    		List<String> taskIds = meetingTaskInfoService.findTaskInfoIdsByApplyRecordIds(id);
    		if(CollectionUtils.isNotEmpty(taskIds)) dataIds.addAll(taskIds);
			attendUser.add(record.getAttendUser());
			emceeUser.add(record.getEmceeUser());
			memoUser.add(record.getMemoUser());
        	this.popUserScopeUtilService.delScopeMethod("oa_meeting_apply_record_scope", attendUser, "oa_meeting_apply_record", "attend_user");
        	this.popUserScopeUtilService.delScopeMethod("oa_meeting_apply_record_scope", emceeUser, "oa_meeting_apply_record", "emcee_user");
        	this.popUserScopeUtilService.delScopeMethod("oa_meeting_apply_record_scope", memoUser, "oa_meeting_apply_record", "memo_user");
        	
        	//删除相关签到信息
        	this.signedInfoService.deleteSignInfo(id);
        	//删除相关定位签到地址信息
        	this.signedAddressService.deleteSignAddress(id);
        	//删除相关通知
        	this.noticeInfoService.deleteByApplyrecord(id);
        	//删除相关会议纪要
        	this.memoInfoService.deleteMemoInfo(id);
        	//删除相关会议任务
            this.meetingTaskInfoService.deleteByRecordId(id);
            this.applyRecordDingService.deleteApplyRecord(id);
            //删除相关会议消息
        	this.meetingSendMsgUtils.deleteMessage(dataIds, corpId, token);
        } catch (Exception e) {
            e.printStackTrace();
            return OperationResult.buildFailureResult("删除会议状失败");
        }
        logger.debug("删除会议状结束");
        return OperationResult.buildSuccessResult("删除会议成功");
    }
    
    /**
     * 提前结束会议
     */
    @ApiOperation(value = "提前结束会议", notes = "")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "id", value = "会议id", required = true, paramType = "body", dataType = "String")
    })
    @RequestMapping(value = "/endApplyRecord", method = RequestMethod.POST)
    public OperationResult endApplyRecord(HttpServletRequest request) {
    	try {
    		String id =  request.getParameter("id");
    		ApplyRecord record = this.applyRecordDingService.findOne(id);
        	if(record != null){
        		record.setStatus(5);
        		String current = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm");
        		record.setEndTime(current);
        		this.applyRecordDingService.save(record);
        	}
    	} catch (Exception e) {
    		e.printStackTrace();
    		return OperationResult.buildFailureResult("操作失败");
    	}
    	return OperationResult.buildSuccessResult("操作成功");
    }

	private String getRequestPayload(HttpServletRequest req) {
		StringBuilder sb = new StringBuilder();
		try {
			BufferedReader reader = req.getReader();
			Throwable localThrowable3 = null;
			try {
				char[] buff = new char[1024];
				int len;
				while ((len = reader.read(buff)) != -1)
					sb.append(buff, 0, len);
			} catch (Throwable localThrowable1) {
				localThrowable3 = localThrowable1;
				throw localThrowable1;
			} finally {
				if (reader != null)
					if (localThrowable3 != null)
						try {
							reader.close();
						} catch (Throwable localThrowable2) {
							localThrowable3.addSuppressed(localThrowable2);
						}
					else
						reader.close();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return sb.toString();
	}
	
	//+++++++++++++++++++++++++++++下面是从ApplyRecordRestApiController类中迁移过来的代码+++++++++++++
	
    @RequestMapping(value = "/applyRecordInfoJob", method = RequestMethod.GET, produces = {
    		"application/json; charset=UTF-8" })
	public OperationResult applyRecordInfoJob(HttpServletRequest request) {
    	logger.info("----applyRecordInfoJob----");
		// 会议管理定时任务 更新会议状态、发送会议提醒消息
		applyRecordService.handleApplyRecord(request);
		logger.info("----applyRecordInfoJob--end--");
		return OperationResult.buildSuccessResult();
	}
    
    @RequestMapping(value = "/joinWebMeetingJob", method = RequestMethod.GET, produces = {
		"application/json; charset=UTF-8" })
	public OperationResult joinWebMeetingJob(HttpServletRequest request) {
	    logger.debug("joinWebMeetingJob---s");
	    // 会议管理定时任务 更新会议状态、发送会议提醒消息
	    applyRecordService.handleJoinQS(request);
	    logger.debug("joinWebMeetingJob--e");
	    return OperationResult.buildSuccessResult();
	}

	@RequestMapping(value = "/taskInfoJob", method = RequestMethod.GET, produces = {
			"application/json; charset=UTF-8" })
	public OperationResult taskInfoJob(HttpServletRequest request) {
		logger.debug("taskInfoJob---s");
		// 会议管理定时任务 更新会议状态、发送会议提醒消息
		this.meetingTaskInfoService.remindTaskInfoJob(request);
		logger.debug("taskInfoJob---e");
		return OperationResult.buildSuccessResult();
	}

	@ApiOperation(value = "日程获取对应条件的会议", notes = "日程获取对应条件的会议")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "corpId", value = "机构ID", required = true, paramType = "path", dataType = "String"),
			@ApiImplicitParam(name = "startTime", value = "开始时间", required = true, paramType = "path", dataType = "String"),
			@ApiImplicitParam(name = "endTime", value = "结束时间", required = true, paramType = "path", dataType = "String"),
			@ApiImplicitParam(name = "title", value = "任务标题", required = true, paramType = "path", dataType = "String"),
			@ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "path", dataType = "String"),
			@ApiImplicitParam(name = "token", value = "token", required = true, paramType = "path", dataType = "String"), })
	@RequestMapping(value = "/queryApplyRecord", method = RequestMethod.GET, produces = {
			"application/json; charset=UTF-8" })
	public OperationResult queryApplyRecordList(HttpServletRequest request) {
		logger.debug("--queryApplyRecordList-----");
		try {
			WebUser user=WebUtils.getCurrentUser();
			String corpId = request.getParameter("corpId");
			String startTime = request.getParameter("startTime");
			String endTime = request.getParameter("endTime");
			String title = request.getParameter("title");
			String userId = request.getParameter("userId");
			String token = request.getParameter("token");
			String userName="";
			long time=System.currentTimeMillis();
			List<Map> list = applyRecordService.queryApplyRecordList(title, startTime, endTime, corpId, userId, token);
			logger.debug("zhaozy:meeting1:"+(System.currentTimeMillis()-time));
			time=System.currentTimeMillis();
			if(user == null) {
				Map<String, Object> userMap=userApiService.getUser(userId, corpId, "", token);
				userName=(String)userMap.get("userName");
			}else {
				userName=user.getUserName();
			}
			//获取京东方会议系统数据
			if(userName!="" ){
				testQueryApplyRecordCount++;
				List<Map<String,Object>>jdfMeetingList=jdfMeetingService.getJdfMeetingListByParam(startTime, endTime, title, userId, userName);
//				logger.error("meetingCallApiCount:testQueryApplyRecordCount:接口调用次数："+testQueryApplyRecordCount+
//						" meetingCallApiCount:testMonthCount:按月查调用次数："+JdfMeetingService.testMonthCount+
//						" meetingCallApiCount:testDayCount:按天查调用次数："+JdfMeetingService.testDayCount+
//						" meetingCallApiCount:testTokenCount:获取token次数："+JdfMeetingService.testTokenCount+
//						" 请求主机："+request.getRemoteHost()+":"+request.getRemotePort());
				list.addAll(jdfMeetingList);
			}
			logger.debug("zhaozy:meeting2:"+(System.currentTimeMillis()-time));
			return OperationResult.buildSuccessResult(list);
		} catch (Exception e) {
			e.printStackTrace();
			return OperationResult.buildFailureResult("接口调用失败");
		}
	}

	@ApiOperation(value = "日程根据会议id获取会议详情", notes = "日程根据会议id获取会议详情")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "corpId", value = "机构ID", required = true, paramType = "path", dataType = "String"),
			@ApiImplicitParam(name = "applyRecordId", value = "会议ID", required = true, paramType = "path", dataType = "String"),
			@ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "path", dataType = "String"),
			@ApiImplicitParam(name = "token", value = "token", required = true, paramType = "path", dataType = "String") })
	@RequestMapping(value = "/queryApplyRecordById", method = RequestMethod.GET, produces = {
			"application/json; charset=UTF-8" })
	public OperationResult queryApplyRecordById(HttpServletRequest request) {
		try {
			WebUser user=WebUtils.getCurrentUser();
			String meetingCode = request.getParameter("meetingCode");
			String applyRecordId = request.getParameter("applyRecordId");
			String token = request.getParameter("token");
			String corpId = request.getParameter("corpId");
			String userId = request.getParameter("userId");
			String type = request.getParameter("jdfType");
			if(StringUtils.isNotBlank(meetingCode) && !"undefined".equals(meetingCode)&& !"null".equals(meetingCode)) {
				
				if(StringUtils.isBlank(type)||"undefined".equals(type) ||"null".equals(type)) {
					type="1";//给个默认值吧
				}
				testQueryApplyRecordByIdCount++;
				Map<String,Object> reBoedata=jdfMeetingService.getMeetingDetailByMeetingCode(meetingCode, user.getUserName(), Integer.valueOf(type));
//				logger.error("meetingCallApiCount:testQueryApplyRecordByIdCount:接口调用次数:"+testQueryApplyRecordByIdCount+
//						" meetingCallApiCount:testMonthCount:按月查调用次数："+JdfMeetingService.testMonthCount+
//						" meetingCallApiCount:testDayCount:按天查调用次数："+JdfMeetingService.testDayCount+
//						" meetingCallApiCount:testTokenCount:获取token次数："+JdfMeetingService.testTokenCount+
//						" 请求主机："+request.getRemoteHost()+":"+request.getRemotePort());
				
				reBoedata.put("currentUserId", userId);
				return OperationResult.buildSuccessResult(reBoedata);
			}
			Map<String, Object> result = new HashMap<String, Object>();
			result.put("currentUserId", userId);
			ApplyRecord applyRecord = this.applyRecordService.findOne(applyRecordId);
			result.put("entity", applyRecord);

			String attachment = StringUtils.null2String(applyRecord.getFileId());
	        if(!"".equals(attachment)){
	                String dataInitList = attchService.getAttachmentInfo(attachment,TOKEN);
	            result.put("attachment", "["+dataInitList+"]");
	        } else {
	        	result.put("attachment", "");
	        }
			if(StringUtils.isNotEmpty(applyRecord.getMeetingTypeId())) {
            	MeetingType mt = meetingTypeService.findOne(applyRecord.getMeetingTypeId());
            	if(mt != null) result.put("meetingType", mt.getTypeName());
            }
			// 会议室查询
			String boardroomName = "无";
			BoardroomSet boardroomSet = null;
			if (StringUtils.isNotEmpty(applyRecord.getBoardroomId())) {
				boardroomSet = this.boardroomSetService.findOne(applyRecord.getBoardroomId());
				if (boardroomSet != null) {
					boardroomName = boardroomSet.getName();
				}
			}
			result.put("boardroomName", boardroomName);
			// 主持人
			String emceeUser = popUserScopeUtilService.getScopeTypeValue("oa_meeting_apply_record_scope", "oa_meeting_apply_record",
					"emcee_user", StringUtils.null2String(applyRecord.getEmceeUser()));
			result.put("emceeUser", emceeUser);
			result.put("emceeUserId", "");
			if (StringUtils.isNotEmpty(emceeUser)) {
				String scopeName = this.userApiService.getScopeName(emceeUser, corpId, token);
				result.put("emceeUserName", scopeName);
				String[] scope = emceeUser.split("SCOPE");
				if (scope.length > 1) {
					result.put("emceeUserId", scope[1]);
				}
			}
			// 纪要员
			String memoUser = popUserScopeUtilService.getScopeTypeValue("oa_meeting_apply_record_scope", "oa_meeting_apply_record",
					"memo_user", StringUtils.null2String(applyRecord.getMemoUser()));
			result.put("memoUser", memoUser);
			if (StringUtils.isNotEmpty(memoUser)) {
				String scopeName = this.userApiService.getScopeName(memoUser, corpId, token);
				result.put("memoUserName", scopeName);
			}
			// 参会人
			String attendUser = popUserScopeUtilService.getScopeTypeValue("oa_meeting_apply_record_scope", "oa_meeting_apply_record",
					"attend_user", StringUtils.null2String(applyRecord.getAttendUser()));
			result.put("attendUser", attendUser);
			if (StringUtils.isNotEmpty(attendUser)) {
				String scopeName = this.userApiService.getScopeName(attendUser, corpId, token);
				result.put("attendUserName", scopeName);
			}
			// 会议列席人
			String attendants = popUserScopeUtilService.getScopeTypeValue("oa_meeting_apply_record_scope", "oa_meeting_apply_record",
					"meeting_attendants", StringUtils.null2String(applyRecord.getMeetingAttendants()));
			result.put("attendants", attendants);
			if (StringUtils.isNotEmpty(attendants)) {
				String scopeName = this.userApiService.getScopeName(attendants, corpId, token);
				result.put("attendantsName", scopeName);
			}
						
			String meetingServe = "";
			if (StringUtils.isNotEmpty(applyRecord.getMeetingServe())) {
				List<ServeSet> serveSetList = this.serveSetService.getServeSetListByIds(applyRecord.getMeetingServe());
				if (serveSetList != null && serveSetList.size() > 0) {
					for (ServeSet s : serveSetList) {
						meetingServe += s.getName() + ",";
					}
					meetingServe = meetingServe.substring(0, meetingServe.length() - 1);
				}
			}
			result.put("meetingServe", meetingServe);
			// 签到地址
			List<SignedAddress> address = this.signedAddressService.findByRecordId(applyRecordId);
			result.put("address", address);
			// 查询基础设置
			String noticeType = commonService.getSysParamValueByMark(corpId, token, "sysImType");
			result.put("noticeType", noticeType);
			return OperationResult.buildSuccessResult(result);
		} catch (Exception e) {
			e.printStackTrace();
			return OperationResult.buildFailureResult("接口调用失败");
		}
	}

	@ApiOperation(value = "日程屏蔽掉此会议数据", notes = "日程屏蔽掉此会议数据")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "applyRecordId", value = "会议ID", required = true, paramType = "path", dataType = "String"), })
	@RequestMapping(value = "/removeMeetingInfo", method = RequestMethod.POST, produces = {
			"application/json; charset=UTF-8" })
	public OperationResult removeMeetingInfo(HttpServletRequest request) {
		try {
			return OperationResult.buildSuccessResult("删除成功");
		} catch (Exception e) {
			e.printStackTrace();
			return OperationResult.buildFailureResult("接口调用失败");
		}
	}
	
	//+++++++++++++++++++++++++++++下面是从SignedInfoApiController类中迁移过来的++++
	/**
	 * 修改会议签到状态
	 */
	@ApiOperation(value = "修改会议签到状态", notes = "会议签到")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "会议签到id", required = true, paramType = "body", dataType = "String"),
    })
    @RequestMapping(value = "/editSignedInfo", method = RequestMethod.POST)
    public OperationResult editSignedInfo(HttpServletRequest request) {
        logger.debug("保存会议签到状态开始");
        try {
            String id = request.getParameter("id");
            this.signedInfoService.editSignedInfo(id);
        } catch (Exception e) {
            e.printStackTrace();
            return OperationResult.buildFailureResult("保存会议签到状态失败");
        }
        logger.debug("保存会议签到状态结束");
        return OperationResult.buildSuccessResult("保存会议签到状态成功");
    }
	
	/**
	 * 修改会议签到状态
	 */
	@ApiOperation(value = "扫码或定位签到", notes = "会议签到")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "会议id", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "signType", value = "签到方式", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "signedAddress", value = "签到地址", required = true, paramType = "body", dataType = "String"),
        @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "String")
    })
	@RequestMapping(value = "/userSigned", method = RequestMethod.GET, produces = {
	"application/json; charset=UTF-8" })
	public OperationResult userSigned(HttpServletRequest request) {
        logger.debug("保存会议签到状态开始");
        Map<String, Object> map = new HashMap<String, Object>();
        try {
        	String userId = request.getParameter("userId");
        	String signType = request.getParameter("signType");
            String id = request.getParameter("id");
            SignedInfo signedInfo = this.signedInfoService.getSignedInfo(userId, id);
            NoticeInfo noticeInfo = this.noticeInfoService.findAttendByApplyrecordId(id, userId, "1");
            if(noticeInfo==null || signedInfo == null){//没有参加会议
            	map.put("status", "-1");
            }else{
            	ApplyRecord record = this.applyRecordDingService.findOne(id);
                String signedTime = StringUtils.null2String(record.getSignedTime());
                int flag = 0;
                if(!"0".equals(signedTime)){
                	String startTime = record.getStartTime() + ":00";
                    Date start = DateUtils.parseTime(startTime);
                    Date signTime = DateUtils.addMinutes(start, -Integer.parseInt(signedTime));
                    flag = DateUtils.truncatedCompareTo(signTime, new Date(), Calendar.MILLISECOND);
                }
                String status = StringUtils.null2String(record.getStatus());
                if("1".equals(status) || "4".equals(status)){
                	if(flag < 1){
                		String signedType = record.getSignedType();
//                		String currentDate = DateUtils.formatTimeNow();
                		Date currentDate = new Date();
                		if("0".equals(signType)){//扫码签到
                			String isSigned = "s";
                    		if("2".equals(signedType)){
                    			String signed = StringUtils.null2String(signedInfo.getIsSigned());
                    			if(signed.indexOf("d") >= 0){//已定位签到
                    				isSigned = "sd";
                    			}
                    		}
                    		signedInfo.setIsSigned(isSigned);
                    		signedInfo.setQrcodeTime(currentDate);
                		}else{//定位签到
                			String isSigned = "d";
                    		if("2".equals(signedType)){
                    			String signed = StringUtils.null2String(signedInfo.getIsSigned());
                    			if(signed.indexOf("s") >= 0){//已扫码签到
                    				isSigned = "sd";
                    			}
                    		}
                    		signedInfo.setIsSigned(isSigned);
                    		signedInfo.setPositionTime(currentDate);
                    		String signedAddress = request.getParameter("signedAddress");
                    		signedInfo.setSignedAddress(signedAddress);
                		}
                    	this.signedInfoService.save(signedInfo);
                    	map.put("status", "0");//签到成功
                    	map.put("isSigned", signedInfo.getIsSigned());//签到成功
                    	map.put("positionTime", currentDate);//签到成功
                    }else{
                    	map.put("status", "1");//没有到签到时间
                    }
                }else if("5".equals(status)){
                	map.put("status", "2");//会议已结束
                }else if("3".equals(status)){
                	map.put("status", "3");//会议已取消
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            return OperationResult.buildFailureResult("保存会议签到状态失败");
        }
        logger.debug("保存会议签到状态结束");
        return OperationResult.buildSuccessResult(map);
    }
	
	/**
     * 修改签到状态
     */
	@ApiOperation(value = "修改签到状态", notes = "手动修改")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "applyRecordId", value = "会议id", required = true, paramType = "body", dataType = "String"),
        @ApiImplicitParam(name = "signedUserIds", value = "签到方式", required = true, paramType = "body", dataType = "String"),
    })
	@RequestMapping(value = "/updateSignInfo", method = RequestMethod.POST, produces = {
	"application/json; charset=UTF-8" })
    public OperationResult updateSignInfo(HttpServletRequest request) {
    	String recordId = ValidateUtils.filter(request.getParameter("applyRecordId"));
    	String signedUserId = StringUtils.null2String(request.getParameter("signedUserIds"));
    	String[] userIds = signedUserId.split(",");
    	for (String userId : userIds) {
    		SignedInfo signedInfo = this.signedInfoService.getSignedInfo(userId, recordId);
        	if(signedInfo == null){
        		signedInfo = new SignedInfo();
        	}
        	ApplyRecord record = this.applyRecordDingService.findOne(recordId);
    		if(record != null){
    			String signedType = record.getSignedType();
//    			String currentDate = DateUtils.formatTimeNow();
    			Date currentDate = new Date();
    			String signed = "";
    			if("0".equals(signedType)){//扫码签到
    				signed = "s";
    				signedInfo.setQrcodeTime(currentDate);
    			}else{
    				if("1".equals(signedType)){//定位签到
    					signed = "d";
    				}else if("2".equals(signedType)){//扫码+定位签到
    					signed = "sd";
    					signedInfo.setQrcodeTime(currentDate);
    				}else if("3".equals(signedType)){//现场签到
    					signed = "xc";
    					signedInfo.setQrcodeTime(currentDate);
    				}
    				signedInfo.setPositionTime(currentDate);
    				List<SignedAddress> list = this.signedAddressService.findByRecordId(recordId);
    				if(list!=null && list.size()>0){
    					SignedAddress address = list.get(0);
    					signedInfo.setSignedAddress(address.getSignedAddress());
    				}
    			}
    			signedInfo.setIsSigned(signed);
    			this.signedInfoService.save(signedInfo);
    		}else{
    			OperationResult.buildFailureResult("保存失败");
    		}
		}
    	return OperationResult.buildSuccessResult("保存成功");
    }
	
	/**
	 * 二维码扫码路由
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/murl", method = RequestMethod.GET, produces = { "application/json; charset=UTF-8" })
	public void urlConvert(HttpServletRequest request, HttpServletResponse response) {
		try {
			String url = "";
			String id = request.getParameter("id");
			Urlconvert urlconvert = this.urlconvertService.findOne(id);
			String agent = request.getHeader("User-Agent").toLowerCase();
			if (agent.indexOf("dingtalk") > 0) {// 钉钉扫码
//				String appUrl = GlobalConstant.getConfig("app.mobile.ding.front.url");
				url = urlconvert.getDingUrl();
			} else if (agent.indexOf("micromessenger") > 0) {// 企业微信扫码
//				String wxUrl = GlobalConstant.getConfig("app.mobile.weixin.front.url");
				url = urlconvert.getWxUrl();
			} else if (agent.indexOf("emp") > 0) {// 移动平台扫码
//				String webOutUrl = GlobalConstant.getConfig("app.mobile.menhu.front.url");
				url = urlconvert.getMhUrl();
			}
			response.sendRedirect(url);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
}